window.addEventListener("load", function () {
	var mySwiper = new Swiper(".swiper", {
		autoplay: true, //可选选项，自动滑动

		pagination: {
			el: ".swiper-pagination",
			clickable: true,
		},
	});

	//如果你初始化时没有定义Swiper实例，后面也可以通过Swiper的HTML元素来获取该实例
	new Swiper(".swiper");
	var mySwiper = document.querySelector(".swiper").swiper;
	mySwiper.slideNext();

	let oldUrl = "";
	$("#apiList li").forEach(function (v) {
		console.log(v);
		// 移入事件
		v.addEventListener("mouseover", function () {
			// 背景变蓝
			this.style.backgroundColor = "#0998ff";
			this.style.color = "#fff";
			// 切换透明图
			// 图片路径
			let imgUrl = this.firstElementChild.src;
			this.firstElementChild.src = imgUrl.replace(".svg", "-c.svg");
			// console.log(imgUrl);
			// 原来路径
			oldUrl = imgUrl;
		});
		// 移出事件
		v.addEventListener("mouseout", function () {
			this.style.backgroundColor = "#fff";
			this.style.color = "#000";
			this.firstElementChild.src = oldUrl;
		});

		// 独角兽轮播
		// 获取节点
		const unicornConts = $(".unicornCont");
		// 默认显示
		unicornConts[0].style.opacity = "1";
		let index = 1;
		this.window.setInterval(function () {
			// 先设置消失
			unicornConts.forEach(function (v) {
				v.style.opacity = "0";
			});
			unicornConts[index].style.opacity = "1";
			index++;
			if (index >= unicornConts.length) {
				index = 0;
			}
		}, 3000);
	});

	// 回到顶部
	// 获取节点
	const backTopNode = $(".backTop");
	window.addEventListener("scroll", function () {
		if (this.scrollY >= 800) {
			backTopNode.style.opacity = 1;
			backTopNode.style.transition = "opacity 1s";
		} else {
			backTopNode.style.opacity = 0;
		}
	});
	// console.log(unicornConts);
	backTopNode.addEventListener("click", function () {
		window.scrollTo({ left: 0, top: 0, behavior: "smooth" });
	});
});
